/*-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License.You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
	
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
	
The Original Code is Fever RS ( ActionScript 3 ) Framework code.
	
The Initial Developer of the Original Code is Romain Ecarnot.
Portions created by Initial Developer are Copyright (C) 2006
the Initial Developer. All Rights Reserved.
	
Contributor(s):
	
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-----------------------------------------------------------------------------*/

package fever.app.context.browser 
{
	import fever.app.context.ApplicationDialog;	import fever.commands.JSCommand;	
	/**
	 * <strong>Web browser</strong> dialog system.
	 * 
	 * @includeExample BrowserDialogSample.as -noswf
	 * 
	 * @see fever.app.context.ApplicationDialog
	 * @see fever.app.core.FeverCore
	 * 
	 * @author Romain Ecarnot
	 */
	public class BrowserDialog implements ApplicationDialog
	{
		//--------------------------------------------------------------------
		// Private properties
		//--------------------------------------------------------------------
		
		private static var _confirmMETHOD : String = "openConfirm";
		private static var _alertMETHOD : String = "openAlert";
		
		private var _openConfirm : JSCommand;
		private var _openAlert : JSCommand;
		
			
		//--------------------------------------------------------------------
		// Public API
		//--------------------------------------------------------------------
		
		/**
		 * @private
		 * Constructor.
		 */
		public function BrowserDialog( )
		{
			_initJSCommand();
		}
		
		/** 
		 * @inheritDoc
		 */
		public function showFileOpenDialog ( caption : String/*, filter : FileFilterCollection, multipleSelect : Boolean, handler : Delegate */ ) : String
		{
			return "";
		}
		
		/** 
		 * @inheritDoc
		 */
		public function showFileSaveDialog (  caption : String/*, filterList : FileFilterCollection, fileName : String, handler : Delegate*/  ) : String
		{
			return "";
		}
		
		/** 
		 * @inheritDoc
		 */
		public function showBrowseFolderDialog (  caption : String/*, handler : Delegate */ ) : String
		{
			return "";
		}
		
		/** 
		 * @inheritDoc
		 */
		public function confirm( text : String, handler : Object = null ) : void
		{
			var b : Boolean = _openConfirm.call( text );
			
			if( handler != null )
			{
				handler.addArguments( b );
				handler.execute();
			}
		}
		
		/** 
		 * @inheritDoc
		 */
		public function alert( text : String, handler : Object = null ) : void
		{
			_openAlert.call( text );
			
			if( handler != null ) handler.execute();
		}
		
		/** 
		 * @inheritDoc
		 */
		public function message( text : String, handler : Object = null ) : void
		{
			alert( text, handler );
		}
		
		
		//--------------------------------------------------------------------
		// Private implementations
		//--------------------------------------------------------------------
		
		private function _initJSCommand() : void
		{
			_openAlert = new JSCommand( 
					_alertMETHOD,
					"( caption ){ return alert( caption ); }"
			);
			
			_openConfirm = new JSCommand( 
				_confirmMETHOD,
				"( caption ){ return confirm( caption ); }"
			);
		}		
	}
}
